<?php

namespace App\Models\Dynamic;


use Illuminate\Database\Eloquent\Model;

class BloodThreshold extends Model
{
    protected $table = "tn_blood_threshold";

    public $timestamps = false;

    protected $fillable = [
        'usertype', 'gettimetype', 'greenlow', 'greenhigh', 'yellowlow', 'yellowhigh', 'redlow', 'redhigh', 'userbaseid', 'sceneid'
    ];


    public function getOneByType($userbase_id, $usertype, $hospital_id, $gettimetype, $type)
    {

        $info = $this->where('usertype', '=', intval($usertype))
            ->where('gettimetype', '=', $gettimetype)
            ->where('userbaseid', '=', $userbase_id)
            ->orderBy('id', 'desc')->first();

        if (!$info) {

            $info = $this->where('usertype', '=', intval($usertype))
                ->where('gettimetype', '=', $gettimetype)
                ->where('userbaseid', '=', 0)
                ->where('sceneid', '=', $hospital_id)
                ->orderBy('id', 'desc')->first();

            if (!$info && $hospital_id != 0) {
                $info = $this->where('usertype', '=', intval($usertype))
                    ->where('gettimetype', '=', $gettimetype)
                    ->where('userbaseid', '=', 0)
                    ->where('sceneid', '=', 0)
                    ->orderBy('id', 'desc')->first();

            }
        }
//        } else if ($type == 1) {
//
//            $info = $this->where('usertype', '=', intval($usertype))
//                ->where('gettimetype', '=', $gettimetype)
//                ->where('userbaseid', '=', $userbase_id)
//                ->orderBy('id', 'desc')->first();
//
//        } else {
//            $info = $this->where('usertype', '=', intval($usertype))
//                ->where('gettimetype', '=', $gettimetype)
//                ->where('userbaseid', '=', $userbase_id)
//                ->where('sceneid', '=', $hospital_id)
//                ->orderBy('id', 'desc')->first();
//
//            if (!$info && $hospital_id != 0) {
//                $info = $this->where('usertype', '=', intval($usertype))
//                    ->where('gettimetype', '=', $gettimetype)
//                    ->where('userbaseid', '=', 0)
//                    ->where('sceneid', '=', 0)
//                    ->orderBy('id', 'desc')->first();
//
//            }
//        }


        return $info;
    }
}
